var BLOG_VALUES=new Array();
var BLOG_LOCKED=new Array();
var BLOG_QTYPE="Section";
/*
 *  Updating values through ajax
 */ 

function BlogResetValue(obj,id,type){

BLOG_QTYPE=type;

if(BLOG_LOCKED[id]==1){
return null;
}

div=$(obj);
tmp=div.text();
BLOG_VALUES[id]=tmp;
BLOG_LOCKED[id]=1;
div.empty();
div.append("<a href='javascript:BlogResetClear(\""+id+"\");'>Close</a>&nbsp;&nbsp;<input type='text' name='input"+id+"' value='"+tmp+"' size='30' ondbclick='javascript:BlogResetProcess(\""+id+"\");' onkeypress='javascript:BlogResetCheck(\""+id+"\",event);'   >");

}

function BlogResetCheck(id,e){
	var charCode; 
    if(e && e.which){
        charCode = e.which;
    }else if(window.event){
        e = window.event;
        charCode = e.keyCode;
    }
	if (charCode==13) {
	BlogResetProcess(id);	
	}
	
	if( e.keyCode==27){
	BlogResetClear(id);
	}
}

function BlogResetProcess(id){
	var val=$("input[@name=input"+id+"]").val();
	var div=$("#item"+id);	
	if(val.length < 1 ) { alert("Value is empty"); return null; }
	// Setting new value
	Azaria.GetContent("blog-ajaxtools","&Reset"+BLOG_QTYPE+"="+id+"&Value="+val);	
	
	div.empty();
	div.append(val);
	BLOG_LOCKED[id]=0;
	
	
}

function BlogResetClear(id){
	var div=$("#item"+id);
	div.empty();
	div.append(BLOG_VALUES[id]);
	BLOG_LOCKED[id]=0;
}

function BlogEmpty(data){
}

/*
 *  Tags autoload 
 */


function BlogTags (obj,e){

$("#spanOutput").css({display:"none"});

var lastChar=DetectChar(e);

lastChar= ( lastChar == null || lastChar == "undefined" || lastChar.length!=1 ) ? null : lastChar; 


var value=obj.value;

if(lastChar!=null) value+=lastChar;


var pieces=value.split(",");

var current=trim(pieces[pieces.length-1]);


if(current.length<1 || current==" ") return null;

/* 
 *  Looking for pieces 
 */
 
var data="";
 
var i=0; 
while(i<TagsArray.length){
	
	if(TagsArray[i].indexOf(current)>=0){
		//$("#j_debug").append("Current - "+current+", Index: "+TagsArray[i]+" indexOf: "+TagsArray[i].indexOf(current)+"<br>");
		data+=" "+TagsArray[i];
	}
	
	i++;
}

BlogTagsAppendData(data);
}

function BlogTagsAppendData(data){
var sX=0;
var sY=0;
var Element=$("#tagField");
var eH=Element.offsetHeight;
var eW=Element.offsetWidth;
while(Element!=null){
sX+=Element.offsetLeft;
sY+=Element.offsetTop;
Element=Element.offsetParent;
}
xp=document.getElementById("spanOutput");
xp.style.left=sX;
xp.style.top=sY+eH;
xp.style.display="block";
xp.innerHTML=data;
}

function DetectChar(e){
	var charCode; 
    if(e && e.which){
        charCode = e.which;
    }else if(window.event){
        e = window.event;
        charCode = e.keyCode;
    }
	if(charCode==8)return null;
	
	return String.fromCharCode(charCode);
}

function BlogSwitch(item){
var content = Azaria.GetContent("blog-ajaxtools","&Response=html&ItemHead="+item);
if(!content){ }
var obj=$("#item_"+item);
obj.empty();
obj.append(content);
var sw=$("#item_switch_"+item);
sw.empty();
sw.append("<a href='javascript:BlogHide(\""+item+"\");'>▼</a>");
}
function BlogHide(item){
var obj=$("#item_"+item);
var sw=$("#item_switch_"+item);
sw.empty();
sw.append("<a href='javascript:BlogSwitch(\""+item+"\");'>▶</a>");
obj.empty();
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

